<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
        <head><title>trait BeforeAndAfter in org.scalatest</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF8"></meta><meta content="scaladoc (version 2.7.2.final)" name="generator"></meta><link href="../../style.css" type="text/css" rel="stylesheet"></link><script type="text/javascript" src="../../script.js"></script>
        </head>
        <body onload="init()">
        <table summary="" class="navigation">
        <tr>
          <td class="navigation-links" valign="top">
            <!-- <table><tr></tr></table> -->
          </td>
          <td align="right" valign="top" style="white-space:nowrap;" rowspan="2">
            <div class="doctitle-larger">ScalaTest 0.9.4</div>
          </td>
        </tr>
        <tr><td></td></tr>
      </table>
        
      <div class="entity">
        <a href="../../org/scalatest$package.html" target="_self">org.scalatest</a>
        <br></br>
        <span class="entity">trait  BeforeAndAfter</span>
      </div><hr></hr>
      <div class="source">
        [source: <a href="" class="org/scalatest/BeforeAndAfter"><code>org/scalatest/BeforeAndAfter.scala</code></a>]
      </div><hr></hr>
      <a name="BeforeAndAfter"></a><dl>
      <dt>
        
        <code></code>
        <code>trait</code>
        <em>BeforeAndAfter</em>
      </dt>
      <dd><code> extends </code><a href="../../org/scalatest/ExecuteAndRun.html" target="_self">ExecuteAndRun</a><code> with </code><a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html" target="_self">AnyRef</a></dd>
    </dl>
      <dl><dd>Trait that can be mixed into suites that need methods invoked before and after executing the
 suite, and/or before and after running each test. This trait facilitates a style of testing in which mutable
 fixture objects held in instance variables are replaced or reinitialized before each test or
 suite. Here's an example:
 
 <pre>
 import org.scalatest._
 import scala.collection.mutable.ListBuffer

 class MySuite extends BeforeAndAfter {

   // Fixtures as reassignable variables and mutable objects
   var sb: StringBuilder = _
   val lb = new ListBuffer[String]
 
   override def beforeEach() {
     sb = new StringBuilder("ScalaTest is ")
     lb.clear()
   }

   def testEasy() {
     sb.append("easy!")
     assert(sb.toString === "ScalaTest is easy!")
     assert(lb.isEmpty)
     lb += "sweet"
   }

   def testFun() {
     sb.append("fun!")
     assert(sb.toString === "ScalaTest is fun!")
     assert(lb.isEmpty)
   }
 }
 </pre>
 
 <p>
 Because this trait invokes <code>super.execute</code> to execute the suite and <code>super.runTest</code> to
 run each test, you may need to mix this trait in last to get the desired behavior. For example, this won't
 work, because <code>BeforeAndAfter</code> is "super" to </code>FunSuite</code>:
 </p>
 <pre>
 class MySuite extends BeforeAndAfter with FunSuite 
 </pre>
 <p>
 You'd need to turn it around, so that <code>FunSuite</code> is "super" to <code>BeforeAndAfter</code>, like this:
 </p>
 <pre>
 class MySuite extends FunSuite with BeforeAndAfter
 </pre>
 <p>

 <p>
 If you want to do something before and after both the tests and the nested <code>Suite</code>s,
 then you can override <code>execute</code> itself, or use the <code>beforeAll</code>
 and <code>afterAll</code> methods of <code>BeforeAndAfter</code>.
 </p></dd></dl>
      <dl><dt style="margin:10px 0 0 20px;">
        <b>Author</b></dt><dd>Bill Venners</dd></dl>
    
      


<table summary="" cellpadding="3" class="member">
      <tr><td class="title" colspan="2">Method Summary</td></tr>
      <tr>
      <td class="modifiers" valign="top"> 
        <code>protected def</code>
      </td>
      <td class="signature">
        <em><a href="../../org/scalatest/BeforeAndAfter.html#afterAll%28%29" target="_self">afterAll</a></em>
         : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
        
        <div>Defines a method to be run after all of this suite's tests and nested suites have
   been executed. This trait's implementation
   of <code>execute</code> invokes this method after executing
   all tests and nested suites, thus this method can be used to tear down a test fixture
   needed by the entire suite. This trait's implementation of this method does nothing.</div>
      </td>
    </tr>
<tr>
      <td class="modifiers" valign="top"> 
        <code>protected def</code>
      </td>
      <td class="signature">
        <em><a href="../../org/scalatest/BeforeAndAfter.html#afterEach%28%29" target="_self">afterEach</a></em>
         : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
        
        <div>Defines a method to be run after each of this suite's tests. This trait's implementation
   of <code>runTest</code> invokes this method after running
   each test, thus this method can be used to tear down a test fixture
   needed by each test. This trait's implementation of this method does nothing.</div>
      </td>
    </tr>
<tr>
      <td class="modifiers" valign="top"> 
        <code>protected def</code>
      </td>
      <td class="signature">
        <em><a href="../../org/scalatest/BeforeAndAfter.html#beforeAll%28%29" target="_self">beforeAll</a></em>
         : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
        
        <div>Defines a method to be run before any of this suite's tests or nested suites are executed. This trait's implementation
   of <code>execute</code> invokes this method before executing
   any tests or nested suites, thus this method can be used to set up a test fixture
   needed by the entire suite. This trait's implementation of this method does nothing.</div>
      </td>
    </tr>
<tr>
      <td class="modifiers" valign="top"> 
        <code>protected def</code>
      </td>
      <td class="signature">
        <em><a href="../../org/scalatest/BeforeAndAfter.html#beforeEach%28%29" target="_self">beforeEach</a></em>
         : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
        
        <div>Defines a method to be run before each of this suite's tests. This trait's implementation
   of <code>runTest</code> invokes this method before running
   each test, thus this method can be used to set up a test fixture
   needed by each test. This trait's implementation of this method does nothing.</div>
      </td>
    </tr>
<tr>
      <td class="modifiers" valign="top"> 
        <code> def</code>
      </td>
      <td class="signature">
        <em><a href="../../org/scalatest/BeforeAndAfter.html#execute%28Option%5BString%5D%2Corg.scalatest.Reporter%2Corg.scalatest.Stopper%2CSet%5BString%5D%2CSet%5BString%5D%2CMap%5BString%2CAny%5D%2COption%5Borg.scalatest.Distributor%5D%29" target="_self">execute</a></em>
        (<em>testName</em> : <a href="" target="contentFrame" class="scala/Option">scala.Option</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>], <em>reporter</em> : <a href="../../org/scalatest/Reporter.html" target="_self">Reporter</a>, <em>stopper</em> : <a href="../../org/scalatest/Stopper.html" target="_self">Stopper</a>, <em>includes</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Set">scala.collection.immutable.Set</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>], <em>excludes</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Set">scala.collection.immutable.Set</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>], <em>properties</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Map">scala.collection.immutable.Map</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html" target="_self">Any</a>], <em>distributor</em> : <a href="" target="contentFrame" class="scala/Option">scala.Option</a>[<a href="../../org/scalatest/Distributor.html" target="_self">Distributor</a>]) : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
        
        <div>Execute a suite surrounded by calls to <code>beforeAll</code> and <code>afterAll</code>.
   This trait's implementation of this method ("this method") invokes <code>beforeAll</code>
   before executing any tests or nested suites and <code>afterAll</code>
   after executing all tests and nested suites. It executes the suite by invoking <code>super.execute</code>, passing along
   the seven parameters passed to it.</div>
      </td>
    </tr>
<tr>
      <td class="modifiers" valign="top"> 
        <code> def</code>
      </td>
      <td class="signature">
        <em><a href="../../org/scalatest/BeforeAndAfter.html#runTest%28String%2Corg.scalatest.Reporter%2Corg.scalatest.Stopper%2CMap%5BString%2CAny%5D%29" target="_self">runTest</a></em>
        (<em>testName</em> : <a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>, <em>reporter</em> : <a href="../../org/scalatest/Reporter.html" target="_self">Reporter</a>, <em>stopper</em> : <a href="../../org/scalatest/Stopper.html" target="_self">Stopper</a>, <em>properties</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Map">scala.collection.immutable.Map</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html" target="_self">Any</a>]) : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
        
        <div>Run a test surrounded by calls to <code>beforeEach</code> and <code>afterEach</code>.
   This trait's implementation of this method ("this method") invokes <code>beforeEach</code>
   before running each test and <code>afterEach</code>
   after running each test. It runs each test by invoking <code>super.runTest</code>, passing along
   the four parameters passed to it.</div>
      </td>
    </tr>
      </table><table summary="" cellpadding="3" class="inherited">
        <tr><td class="title" colspan="2">
          Methods inherited from <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html" target="_self">AnyRef</a>
        </td></tr>
        <tr><td class="signature" colspan="2">
          <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#getClass%28%29" target="_self">getClass</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#hashCode%28%29" target="_self">hashCode</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#equals%28Any%29" target="_self">equals</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#clone%28%29" target="_self">clone</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#toString%28%29" target="_self">toString</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#notify%28%29" target="_self">notify</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#notifyAll%28%29" target="_self">notifyAll</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#wait%28Long%29" target="_self">wait</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#wait%28Long%2CInt%29" target="_self">wait</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#wait%28%29" target="_self">wait</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#finalize%28%29" target="_self">finalize</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#%3D%3D%28AnyRef%29" target="_self">==</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#%21%3D%28AnyRef%29" target="_self">!=</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#eq%28AnyRef%29" target="_self">eq</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#ne%28AnyRef%29" target="_self">ne</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/AnyRef.html#synchronized%28T0%29" target="_self">synchronized</a>
        </td></tr>
      </table><table summary="" cellpadding="3" class="inherited">
        <tr><td class="title" colspan="2">
          Methods inherited from <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html" target="_self">Any</a>
        </td></tr>
        <tr><td class="signature" colspan="2">
          <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html#%3D%3D%28Any%29" target="_self">==</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html#%21%3D%28Any%29" target="_self">!=</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html#isInstanceOf" target="_self">isInstanceOf</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html#asInstanceOf" target="_self">asInstanceOf</a>
        </td></tr>
      </table>


      


<table summary="" cellpadding="3" class="member-detail">
          <tr><td class="title">Method Details</td></tr>
        </table><div><a name="beforeEach%28%29"></a><dl>
      <dt>
        
        <code>protected</code>
        <code>def</code>
        <em>beforeEach</em> : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
      </dt>
      <dd></dd>
    </dl>
      <dl><dd>Defines a method to be run before each of this suite's tests. This trait's implementation
   of <code>runTest</code> invokes this method before running
   each test, thus this method can be used to set up a test fixture
   needed by each test. This trait's implementation of this method does nothing.</dd></dl>
      <dl></dl>
    <hr></hr>
<a name="afterEach%28%29"></a><dl>
      <dt>
        
        <code>protected</code>
        <code>def</code>
        <em>afterEach</em> : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
      </dt>
      <dd></dd>
    </dl>
      <dl><dd>Defines a method to be run after each of this suite's tests. This trait's implementation
   of <code>runTest</code> invokes this method after running
   each test, thus this method can be used to tear down a test fixture
   needed by each test. This trait's implementation of this method does nothing.</dd></dl>
      <dl></dl>
    <hr></hr>
<a name="beforeAll%28%29"></a><dl>
      <dt>
        
        <code>protected</code>
        <code>def</code>
        <em>beforeAll</em> : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
      </dt>
      <dd></dd>
    </dl>
      <dl><dd>Defines a method to be run before any of this suite's tests or nested suites are executed. This trait's implementation
   of <code>execute</code> invokes this method before executing
   any tests or nested suites, thus this method can be used to set up a test fixture
   needed by the entire suite. This trait's implementation of this method does nothing.</dd></dl>
      <dl></dl>
    <hr></hr>
<a name="afterAll%28%29"></a><dl>
      <dt>
        
        <code>protected</code>
        <code>def</code>
        <em>afterAll</em> : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
      </dt>
      <dd></dd>
    </dl>
      <dl><dd>Defines a method to be run after all of this suite's tests and nested suites have
   been executed. This trait's implementation
   of <code>execute</code> invokes this method after executing
   all tests and nested suites, thus this method can be used to tear down a test fixture
   needed by the entire suite. This trait's implementation of this method does nothing.</dd></dl>
      <dl></dl>
    <hr></hr>
<a name="runTest%28String%2Corg.scalatest.Reporter%2Corg.scalatest.Stopper%2CMap%5BString%2CAny%5D%29"></a><dl>
      <dt>
        
        <code></code>
        <code>def</code>
        <em>runTest</em>(<em>testName</em> : <a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>, <em>reporter</em> : <a href="../../org/scalatest/Reporter.html" target="_self">Reporter</a>, <em>stopper</em> : <a href="../../org/scalatest/Stopper.html" target="_self">Stopper</a>, <em>properties</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Map">scala.collection.immutable.Map</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html" target="_self">Any</a>]) : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
      </dt>
      <dd></dd>
    </dl>
      <dl><dd>Run a test surrounded by calls to <code>beforeEach</code> and <code>afterEach</code>.
   This trait's implementation of this method ("this method") invokes <code>beforeEach</code>
   before running each test and <code>afterEach</code>
   after running each test. It runs each test by invoking <code>super.runTest</code>, passing along
   the four parameters passed to it.
   
   <p>
   If any invocation of <code>beforeEach</code> completes abruptly with an exception, this
   method will complete abruptly with the same exception. If any call to
   <code>super.runTest</code> completes abruptly with an exception, this method
   will complete abruptly with the same exception, however, before doing so, it will
   invoke <code>afterEach</code>. If <cod>afterEach</code> <em>also</em> completes abruptly with an exception, this 
   method will nevertheless complete abruptly with the exception previously thrown by <code>super.runTest</code>.
   If <code>super.runTest</code> returns normally, but <code>afterEach</code> completes abruptly with an
   exception, this method will complete abruptly with the same exception.
   </p></dd></dl>
      <dl></dl>
    <dl>
        <dt style="margin:10px 0 0 20px;">
          <b>Overrides</b>
        </dt>
        <dd>
        <a href="../../org/scalatest/ExecuteAndRun.html" target="_self">ExecuteAndRun</a>.<a href="../../org/scalatest/ExecuteAndRun.html#runTest%28String%2Corg.scalatest.Reporter%2Corg.scalatest.Stopper%2CMap%5BString%2CAny%5D%29" target="_self">runTest</a>
        </dd>
      </dl><hr></hr>
<a name="execute%28Option%5BString%5D%2Corg.scalatest.Reporter%2Corg.scalatest.Stopper%2CSet%5BString%5D%2CSet%5BString%5D%2CMap%5BString%2CAny%5D%2COption%5Borg.scalatest.Distributor%5D%29"></a><dl>
      <dt>
        
        <code></code>
        <code>def</code>
        <em>execute</em>(<em>testName</em> : <a href="" target="contentFrame" class="scala/Option">scala.Option</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>], <em>reporter</em> : <a href="../../org/scalatest/Reporter.html" target="_self">Reporter</a>, <em>stopper</em> : <a href="../../org/scalatest/Stopper.html" target="_self">Stopper</a>, <em>includes</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Set">scala.collection.immutable.Set</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>], <em>excludes</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Set">scala.collection.immutable.Set</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>], <em>properties</em> : <a href="" target="contentFrame" class="scala/collection/immutable/Map">scala.collection.immutable.Map</a>[<a href="" target="contentFrame" class="java/lang/String">java.lang.String</a>, <a href="http://www.scala-lang.org/docu/files/api/scala/Any.html" target="_self">Any</a>], <em>distributor</em> : <a href="" target="contentFrame" class="scala/Option">scala.Option</a>[<a href="../../org/scalatest/Distributor.html" target="_self">Distributor</a>]) : <a href="http://www.scala-lang.org/docu/files/api/scala/Unit.html" target="_self">Unit</a>
      </dt>
      <dd></dd>
    </dl>
      <dl><dd>Execute a suite surrounded by calls to <code>beforeAll</code> and <code>afterAll</code>.
   This trait's implementation of this method ("this method") invokes <code>beforeAll</code>
   before executing any tests or nested suites and <code>afterAll</code>
   after executing all tests and nested suites. It executes the suite by invoking <code>super.execute</code>, passing along
   the seven parameters passed to it.
   
   <p>
   If any invocation of <code>beforeAll</code> completes abruptly with an exception, this
   method will complete abruptly with the same exception. If any call to
   <code>super.execute</code> completes abruptly with an exception, this method
   will complete abruptly with the same exception, however, before doing so, it will
   invoke <code>afterAll</code>. If <cod>afterAll</code> <em>also</em> completes abruptly with an exception, this 
   method will nevertheless complete abruptly with the exception previously thrown by <code>super.execute</code>.
   If <code>super.execute</code> returns normally, but <code>afterAll</code> completes abruptly with an
   exception, this method will complete abruptly with the same exception.
   </p></dd></dl>
      <dl></dl>
    <dl>
        <dt style="margin:10px 0 0 20px;">
          <b>Overrides</b>
        </dt>
        <dd>
        <a href="../../org/scalatest/ExecuteAndRun.html" target="_self">ExecuteAndRun</a>.<a href="../../org/scalatest/ExecuteAndRun.html#execute%28Option%5BString%5D%2Corg.scalatest.Reporter%2Corg.scalatest.Stopper%2CSet%5BString%5D%2CSet%5BString%5D%2CMap%5BString%2CAny%5D%2COption%5Borg.scalatest.Distributor%5D%29" target="_self">execute</a>
        </dd>
      </dl><hr></hr></div>


    <hr></hr>
        <div>Copyright (C) 2001-2008 Artima, Inc. All rights reserved.</div><table summary="" class="navigation">
        <tr>
          <td class="navigation-links" valign="top">
            <!-- <table><tr></tr></table> -->
          </td>
          <td align="right" valign="top" style="white-space:nowrap;" rowspan="2">
            <div class="doctitle-larger">ScalaTest 0.9.4</div>
          </td>
        </tr>
        <tr><td></td></tr>
      </table>
      </body>
      </html>